function HandlePagePaymentBonus(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  
  this._createElements();
}

HandlePagePaymentBonus.prototype._createElements = function() {
  var tr, td;

  tr = this._gui.main.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.textAlign = 'center';
  td.style.backgroundColor = '#ffffff';
  td.colSpan = 8;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePagePaymentBonus.prototype._loadData = function() {
  this._orders = null;
  this._parameters = null;
  this._retrieveCustomers(1);
};

HandlePagePaymentBonus.prototype._verifyData = function() {
  if (this._orders) {
    this._updateElements();
  }
};

HandlePagePaymentBonus.prototype._retrieveCustomers = function(page) {
  var _self = this;
  var args = '&p=' + page + '&s=20';
  new RequestUtils()._mysql('paymentbonus', args, function(result, params) { _self._orders = result.data;
                                                                             _self._parameters = result;
                                                                             _self._verifyData.call(_self);
                                                                           }, null);
};

HandlePagePaymentBonus.prototype._updateElements = function() {
  var unique, _self = this, unique = MiscUtils.unique();
  DOMUtils.removeChildElements(this._gui.page);
  DOMUtils.removeTableRows(this._gui.main, 1);
  DOMUtils.removeChildElements(this._gui.checkAll);
  this._selects = [];
  
  this._gui.save.onclick = function() { if (_self._selects.length == 0) {
                                          window.alert('No Items Selected');
                                          return;
                                        }
                                        var orders = [];
                                        for(var i = 0, il = _self._selects.length; i < il; i++) {
                                          var object = _self._selects[i];
                                          orders[orders.length] = object.id;
                                        }
                                        new RequestUtils()._mysql('bonuspaid', '&o=' + JSON.stringify(orders), function(result, params) { _self._retrieveCustomers(1); }, { pos: DOMUtils.findPos(this) });
                                      };
  
  if (this._orders.length == 0) {
    tr = this._gui.main.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = '25px';
    td.style.textAlign = 'center';
    td.style.backgroundColor = '#ffffff';
    td.style.borderRight = 'solid 1px #694247';
    td.colSpan = 8;
    td.appendChild(document.createTextNode('N/A'));
  }

  for(var i = 0, il = this._orders.length; i < il; i++) {
    var order = this._orders[i];
    tr = this._gui.main.insertRow(-1);
    tr.style.backgroundColor = (tr.rowIndex % 2 == 0) ? '#faf9f4' : '#ffffff';
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #7a5052';
    td.style.textAlign = 'center';
    var check = DOMUtils.createInput(null, unique + '_' + i, 'checkbox', '', null);
    check._order = order;
    check.onclick = function() { if (this.checked ==  true) {
                                   _self._selects[_self._selects.length] = this._order;
                                 } else {
                                   MiscUtils.remove(_self._selects, this._order, 'trackId');
                                 }
                               };
    td.appendChild(check);
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #7a5052';
    td.style.height = '25px';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    var a = document.createElement('a');
    a.href = '#';
    a._c = order;
    a.appendChild(document.createTextNode(DlmanageUtils.customerId(order.customerId) + order.flag));
    a.onclick = function() {location.href = '?p=pageadmin&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: this._c.customerId, track: this._c.trackId, isAdmin: true }); return false;};
    td.appendChild(a);
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #7a5052';
    td.style.height = '25px';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    td.appendChild(document.createTextNode(SimpleDate.format(order.createdDate)));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #7a5052';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    td.appendChild(document.createTextNode(SimpleDate.format(order.date)));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #7a5052';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    td.appendChild(document.createTextNode('$' + order.price));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #7a5052';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    td.appendChild(document.createTextNode('$' + order.payment.toFixed(2)));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #7a5052';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode((order.price == 0) ? '0.00%' : ((order.payment / order.price) * 100).toFixed(2) + '%'));
  }
  
  this._gui.checkAll.checked = false;
  this._gui.checkAll._unique = unique;
  this._gui.checkAll.onclick = function() { if (this.checked == true) {
                                             for (var i = 0, il = _self._orders.length; i < il; i++) {
                                                var object = _self._orders[i];
                                                if (document.getElementById(this._unique + '_' + i) && !document.getElementById(this._unique + '_' + i).checked) {
                                                  _self._selects[_self._selects.length] = object;
                                                  document.getElementById(this._unique + '_' + i).checked = true;
                                                }
                                              }
                                            } else {
                                              for (var i = 0, il = _self._orders.length; i < il; i++) {
                                                var object = _self._orders[i];
                                                if (document.getElementById(this._unique + '_' + i)) {
                                                  MiscUtils.remove(_self._selects, object, 'trackId');
                                                  document.getElementById(this._unique + '_' + i).checked = false;
                                                }
                                              }
                                            }
                                          };
                                          
};
